<template>
	<view class="scroll-v">
		<view class="list" v-if="companyList.length > 0">
			<block v-for="(item,index) in companyList" :key="index">
				<MyCompanyItem :item="item" />
			</block>
			<view class="loadStatus">{{loadStatus}}</view>
		</view>
		<loading v-else-if="firstload"></loading>
		<!-- 无内容默认 -->
		<no-thing v-else></no-thing>

	</view>
</template>

<script>
	import loading from "../../components/common/loading.vue";
	import noThing from "../../components/common/no-thing.vue";
	import PositionTaskItem from "../../components/item/position-task-item.vue"
	import MyCompanyItem from '../../components/item/my-company-item.vue'
	export default {
		components: {
			loading,
			noThing,
			MyCompanyItem,
			PositionTaskItem
		},
		data() {
			return {
				showCompanyInfo: false,
				is_personal: false,
				firstload: true,
				groupId: '',
				token: '',
				page: 1,
				postName: '', //岗位名称
				// 招聘状态
				index: -1,
				status: [],
				// 企业选择
				company: [],
				index1: -1,
				loadStatus: "",
				// 接受后台返回的列表参数
				companyList: [],
				// 请求后台需要的数据
				status_id: '', //招聘状态id
				company_id: '', //企业选择id
				companyInfo: {},
			}
		},
		onLoad(option) {
		},
		onPullDownRefresh() {
			this._onRefresh();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.loadMore();
		},
		methods: {
			onNavigate() {
				uni.navigateTo({
					url: '/pages/publish/addRecruitmentPosition'
				})
			},
			// 上拉刷新
			_onRefresh() {
				this.page = 1;
				this.getList();
				// console.log('_onRefresh---->', '_onRefresh');
			},
			// 请求列表
			async getList() {
				// 发请求
				let url = this.ServicesApi.my_company_list;
				let data = {
					limit: 10,
					page: this.page,
				};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					if (this.company_id) {
						this.companyInfo = result.data.company_info;
						this.showCompanyInfo = true;
					}
					this.companyList = result.data.data;
					this.firstload = false;
				} else {
					this.firstload = false;
					uni.stopPullDownRefresh();
				}
			},
			// 上拉加载
			async loadMore() {
				this.loadStatus = "加载中..."
				this.page++;
				let url = this.ServicesApi.my_company_list;
				let data = {
					limit: 10,
					page: this.page,
				};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					let arr = result.data.data;
					this.companyList.push(...arr)
					if (arr.length < 10) {
						this.loadStatus = "没有更多数据"
					}
				} else {
					this.loadStatus = "没有更多数据"
				}
			},
		},
		mounted() {
			this.getList();
		},
		onShow: function(e) {
			// #ifndef H5
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			if (currPage.data && currPage.data.isDoRefresh == true) {
				currPage.data.isDoRefresh = false;
				this._onRefresh();
			} else {
				//不用刷新
			}
			// #endif
			// #ifdef H5
			this._onRefresh()
			// #endif
		}
	}
</script>

<style scoped lang="stylus">
	.company-info-view {
		padding: 30rpx;
		background: #fff;

		.company-title {
			margin-bottom: 30rpx;

			.title-lable {
				color: #666666;
				font-size: 30rpx;
				margin-right: 10rpx;
			}

			.title-value {
				color: #368AED;
				font-size: 36rpx;
			}
		}

		.company-talent-count {
			padding: 30rpx;
			height: 260rpx;
			overflow: hidden;
			border-radius: 10rpx;
			background-image: url('~@/static/img/img_bg_company_info.png');
			background-repeat: no-repeat;
			background-size: 100%;

			.wrap-title-view {
				.horizontal-line {
					width: 80rpx;
					background: #fff;
				}

				.wrap-title {
					color: #fff;
					margin: 0 30rpx;
					font-size: 30rpx;
				}
			}

			.wrap-con-view {
				margin-top: 40rpx;

				.count-item-view {
					flex: 1;
					color: #fff;

					.count-item-num {
						font-size: 36rpx;
						font-weight: 700;
					}

					.count-item-title {
						font-size: 32rpx;
					}
				}
			}
		}
	}

	.loadStatus {
		color: #ccc;
		font-size: 30upx;
		margin-top: 20upx;
		text-align: center;
		margin-bottom: 20upx;
	}

	.scroll-v {
		height: 100vh;
	}

	.btm-btn-box {
		justify-content space-around;
		margin: 30upx 0;

		.btm-btn {
			height: 50upx;
			width: 100upx;
			background: #007AFF;
			color: #fff;
			text-align: center;
			line-height: 50upx;
			font-size: 20upx;
		}
	}

	.btn-add {
		height: 100upx;
		width: 300upx;
		background: #007AFF;
		color: #fff;
		text-align: center;
		line-height: 100upx;
		margin: 30upx auto;
	}

	.list-box {
		padding: 20upx;
		margin: 40upx 0;
		background: #fff;
	}
</style>
